package com.itheima.utils;

import com.itheima.enums.RedisEnum;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.Set;


/**
 * redis清楚对应的缓存
 */
@Component
public class RedisUtil {

    public static RedisUtil redisUtil;
    @Resource
    private RedisTemplate redisTemplate;
    @PostConstruct
    public void init() {
        redisUtil = this;
        redisUtil.redisTemplate = this.redisTemplate;

    }

    /**
     * 删除所有组织的子结构
     */
    public static void deleteOrganizationStructure(){
        Set<String> keys = redisUtil.redisTemplate.keys(RedisEnum.ORGANIZATION.getRedis() + "*");
        redisUtil.redisTemplate.delete(keys);
    }
}
